#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：data_filter 
@File ：main.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/2/24 0:46 
"""

import socket
import message_handler


def main():
	# 设置监听端口
	host = '127.0.0.1'
	port = 12345

	# 创建socket对象
	server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	server_socket.bind((host, port))
	server_socket.listen(5)

	print(f"Listening on {host}:{port}...")

	while True:
		client_socket, addr = server_socket.accept()
		print(f"Connection from {addr}")

		# 接收数据
		data = client_socket.recv(1024).decode('utf-8')
		print(data)

		# 处理数据
		handler = message_handler.MessageHandler()
		handler.handle_message(data)

		client_socket.close()


if __name__ == "__main__":
	main()
